package com.myres.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;

public class User extends BasicObject {
	public static final long serialVersionUID = 543442321l;
	public static final int FEMALE = 1;
	public static final int MALE = 0;
	public static final int ROLE_BUYER = 2;
	public static final int ROLE_SALER = 3;
	public static final int ROLE_MANAGER = 4;
	/**
	 * the name of this user,will be displayed
	 */
	private String name;
	/**
	 * the password
	 */
	private String password;
	/**
	 * the email ,which will be login identity
	 */
	private String email;
	/**
	 * the mobile ,maybe login identity
	 */
	private String mobile;
	/**
	 * the address value
	 */
	private String address;
	/**
	 * the gender can be MALE ,FEMALE
	 */
	private byte gender;
	/**
	 * the age of the user
	 */
	private int age;
	/**
	 * the career of the user
	 */
	private String career;
	/**
	 * remainging score
	 */
	private int score;
	/**
	 * the rank of this user
	 */
	private int rank;
	/**
	 * when becomes user
	 */
	private java.sql.Timestamp when;
	/**
	 * the expire time of smsToken
	 */
	private java.sql.Timestamp temp_expire;
	private java.sql.Timestamp expire;
	/**
	 * the smsToken of this user
	 */
	private String smsToken;
	/**
	 * the login token by client
	 */
	private String token;
	/**
	 * the recommender of this user
	 */
	private int recommenderId;
	/**
	 * the markerterId of this user,all user can be newer's recommender
	 */
	private String marketerId;
	/**
	 * the role of this user,maybe SALER,BUYER,MANAGER
	 */
	private int role;
	private User recommender;

	public int getRecommenderId() {
		return recommenderId;
	}

	public void setRecommenderId(int recommenderId) {
		this.recommenderId = recommenderId;
	}

	public User getRecommender() {
		return recommender;
	}

	public void setRecommender(User recomender) {
		this.recommender = recomender;
		if(recommender !=null)this.recommenderId = recomender.getRecommenderId();
	}

	public int getRole() {
		return role;
	}

	public void setRole(int role) {
		this.role = role;
	}

	public String getSmsToken() {
		return smsToken;
	}

	public void setSmsToken(String smsToken) {
		this.smsToken = smsToken;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getMarketerId() {
		return marketerId;
	}

	public void setMarketerId(String marketerId) {
		this.marketerId = marketerId;
	}

	public java.sql.Timestamp getExpire() {
		return expire;
	}

	public void setExpire(java.sql.Timestamp expire) {
		this.expire = expire;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public byte getGender() {
		return gender;
	}

	public void setGender(byte gender) {
		this.gender = gender;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getCareer() {
		return career;
	}

	public void setCareer(String career) {
		this.career = career;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getRank() {
		return rank;
	}

	public void setRank(int rank) {
		this.rank = rank;
	}

	public java.sql.Timestamp getWhen() {
		return when;
	}

	public void setWhen(java.sql.Timestamp when) {
		this.when = when;
	}

	public boolean isSmsTokenExpire() {
		if (this.getExpire().after(new Date()))
			return false;
		return true;
	}

	public static List<User> populate(ResultSet rs) throws SQLException {
		List<User> list = new ArrayList<User>();
		while (rs.next()) {
			User user = new User();
			user.setId(rs.getInt(1));
			user.setNO(rs.getString(2));
			user.setName(rs.getString(3));
			user.setPassword(rs.getString(4));
			user.setEmail(rs.getString(5));
			user.setMobile(rs.getString(6));
			user.setAddress(rs.getString(7));
			user.setGender(rs.getByte(8));
			user.setAge(rs.getInt(9));
			user.setCareer(rs.getString(10));
			user.setScore(rs.getInt(11));
			user.setRank(rs.getInt(12));
			user.setWhen(rs.getTimestamp(13));
			user.setSmsToken(rs.getString(14));
			user.setToken(rs.getString(15));
			user.setExpire(rs.getTimestamp(16));
			user.setRecommenderId(rs.getInt(17));
			user.setMarketerId(rs.getString(18));
			user.setRole(rs.getInt(19));
			list.add(user);
		}
		return list;
	}
	//these below is modified by hikui
	private Set<Shop> shops;
	private Set<Message> sendMessages;
	private Set<Bulk> bulks;
	private Set<User> recommendedUsers;
	private Set<Message> receiveMessages;
	private Set<Critic> critics;
	private Set<Score> scores;
	private Set<Address> addresses;
	private Set<User> recomendedUser;
	

	public Set<User> getRecomendedUser() {
		return recomendedUser;
	}

	public void setRecomendedUser(Set<User> recomendedUser) {
		this.recomendedUser = recomendedUser;
	}

	public Set<Shop> getShops() {
		return shops;
	}

	public void setShops(Set<Shop> shops) {
		this.shops = shops;
	}

	public Set<Message> getSendMessages() {
		return sendMessages;
	}

	public void setSendMessages(Set<Message> sendMessages) {
		this.sendMessages = sendMessages;
	}

	public Set<Bulk> getBulks() {
		return bulks;
	}

	public void setBulks(Set<Bulk> bulks) {
		this.bulks = bulks;
	}


	public Set<Message> getReceiveMessages() {
		return receiveMessages;
	}

	public void setReceiveMessages(Set<Message> receiveMessages) {
		this.receiveMessages = receiveMessages;
	}

	public Set<Critic> getCritics() {
		return critics;
	}

	public void setCritics(Set<Critic> critics) {
		this.critics = critics;
	}

	public Set<Score> getScores() {
		return scores;
	}

	public void setScores(Set<Score> scores) {
		this.scores = scores;
	}

	public Set<Address> getAddresses() {
		return addresses;
	}

	public void setAddresses(Set<Address> addresses) {
		this.addresses = addresses;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public void setTemp_expire(java.sql.Timestamp temp_expire) {
		this.temp_expire = temp_expire;
	}

	public java.sql.Timestamp getTemp_expire() {
		return temp_expire;
	}
	
	//modify end
}
